// 开发文档: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
module.exports = {
	async add(val) {
		const db = uniCloud.database()
		const res = await db.collection("community").add({
			...val
		})
		return res
	},
	async get() {
		const db = uniCloud.database()
		const res = await db.collection("community").get()
		return res
	},
	async remove(val) {
		const db = uniCloud.database()
		const res = await db.collection("community").get()
		let arr = []
		res.data.forEach((item) => {
			let time = Date.parse(item.createTime.split(" ")[0])
			if (time < val) {
				arr.push(item)
			}
		})
		arr.forEach((mn) => {
			db.collection("community").where({
				_id: mn._id
			}).remove()
		})
		return {
			msg:"删除成功"
		}
	},
	async withdraw(val){
		const db = uniCloud.database()
		const res = db.collection("community").where({
			_id:val
		}).remove()
		return res
	}
}
